package com.dehui.traders.ui.fragment;

import android.view.View;
import android.widget.AdapterView;

import com.dehui.traders.BR;
import com.dehui.traders.R;
import com.dehui.traders.adapter.HomeDataAdapter;
import com.dehui.traders.databinding.FragmentHomeBinding;
import com.dehui.traders.kchart.MyCombinedChartX;
import com.dehui.traders.ui.viewmodle.HomeViewModel;
import com.dehui.traders.widgets.HomeReView;

import java.util.ArrayList;
import me.goldze.mvvmhabit.base.BaseFragment;

/**
 * Created by hqq on 18.3.29.
 */

public class HomeFragment extends BaseFragment<FragmentHomeBinding,HomeViewModel> implements AdapterView.OnItemClickListener, HomeReView.OnRecyclerViewChangeListener {

    private HomeDataAdapter homeAdapter;
    private MyCombinedChartX mChartVolume;
    private HomeViewModel viewModel;

    @Override
    public int initContentView() {
        return R.layout.fragment_home;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public HomeViewModel initViewModel() {
        viewModel = new HomeViewModel(getContext());
        return viewModel;
    }

    @Override
    public void initData() {
        initChart();
        ArrayList<String> list = new ArrayList<>();
        for (int i= 0; i < 10; i++){
            list.add("位置" + i);
        }
        homeAdapter = new HomeDataAdapter(getContext(), list, R.layout.list_item_home_data,this);
        binding.rvHome.setAdapter(homeAdapter);
        binding.rvHome.setOnRecyclerViewChangeListener(this);

    }

    private void initChart() {
        mChartVolume = binding.mycombinedchartKLine;
        viewModel.initChart(mChartVolume);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        homeAdapter.setSelectPos(position);
    }

    @Override
    public void visityPositionChange(int position) {
        homeAdapter.setSelectPos(position);
    }

}
